package frontend.parser.node.decl;

import frontend.parser.node.Node;

import java.util.ArrayList;

public abstract class AbstractInitVal<T extends Node> extends Node {
    protected int dimension;
    protected T valExp_dim0;
    protected ArrayList<T> valExp_dim1;
    protected ArrayList<ArrayList<T>> valExp_dim2;
    public void setDimension(int dimension) {
        this.dimension = dimension;
        switch (dimension) {
            case 0 -> {
                this.valExp_dim0 = null;
            }
            case 1 -> {
                this.valExp_dim1 = new ArrayList<>();
            }
            case 2 -> {
                this.valExp_dim2 = new ArrayList<>();
            }
        }
    }
    public void dim2NewArray() {
        this.valExp_dim2.add(new ArrayList<>());
    }
    public void addValExp(T t) {
        switch (dimension) {
            case 0 -> {
                this.valExp_dim0 = t;
            }
            case 1 -> {
                this.valExp_dim1.add(t);
            }
            case 2 -> {
                this.valExp_dim2.get(valExp_dim2.size() - 1).add(t);
            }
        }
    }

    public int getDimension() {
        return dimension;
    }

    public T getValExp_dim0() {
        return valExp_dim0;
    }

    public ArrayList<T> getValExp_dim1() {
        return valExp_dim1;
    }

    public ArrayList<ArrayList<T>> getValExp_dim2() {
        return valExp_dim2;
    }
}
